import axios from 'axios';
import {API_NEW_VERSION} from '../api';
var qs = require('qs');

const LINE_RULE_FREIGHTS = API_NEW_VERSION + 'line_rule_freights';
const LINE_RULE_FREIGHT = API_NEW_VERSION + 'line_rule_freights/';
const LINE_RULE_FREIGHTS_MODIFY_IS_START = API_NEW_VERSION + 'line_rule_freights_modify_id_start';
const LINE_RULE_FREIGHT_DETAILS = API_NEW_VERSION + 'line_rule_freights_details';
const LINE_RULE_FREIGHT_DETAIL = API_NEW_VERSION + 'line_rule_freights_details/';
const LINE_RULE_FREIGHTS_MODIFY_STATUS = API_NEW_VERSION + 'line_rule_freights_modify_status';
// 获取优惠列表
export const searchLineRuleFreight = params => {
  return axios.get(LINE_RULE_FREIGHTS, {params: params});
};
// 保存优惠线路
export const saveLineRuleFreight = (params) => {
  return axios.post(LINE_RULE_FREIGHTS, params);
};
// 删除优惠线路
export const deleteLineRuleFreight = id => {
  return axios.delete(LINE_RULE_FREIGHT + id);
};
// 根据ID更改优惠线路的开启/禁用状态
export const batchStart = (id, isStart) => {
  return axios.post(LINE_RULE_FREIGHTS_MODIFY_IS_START, qs.stringify({id: id, isStart: isStart}));
};
// 根据ID获取优惠线路
export const getLineRuleFreight = id => {
  return axios.get(LINE_RULE_FREIGHT + id);
};
// 根据优惠线路ID获取优惠列表详情
export const searchLineRuleFreightDetail = params => {
  return axios.get(LINE_RULE_FREIGHT_DETAILS, {params: params});
};
// 根据线路优惠id,更改线路优惠状态
export const changeStatus = (id, status) => {
  return axios.post(LINE_RULE_FREIGHTS_MODIFY_STATUS, qs.stringify({id: id, status: status}));
};
export const saveLineRuleFreightDetail = (params) => {
  return axios.post('/api/v2.0/admin/line_rule_freights/' + params.lineRuleFreightId + '/details', params);
};
// 根据ID获取优惠线路详情
export const getLineRuleFreightDetail = id => {
  return axios.get(LINE_RULE_FREIGHT_DETAIL + id);
};
// 删除优惠线路详情
export const deleteLineRuleFreightDetail = id => {
  return axios.delete(LINE_RULE_FREIGHT_DETAIL + id);
};
// 删除优惠线路详情
export const modifyLineRuleFreightDetail = (id, row) => {
  return axios.post(LINE_RULE_FREIGHT_DETAIL + id, row);
};
